package com.atguigu.ggkt.order.service.impl;

import com.atguigu.ggkt.client.sequence.SequenceFeignClient;
import com.atguigu.ggkt.utils.Base64FileConversion;
import com.atguigu.ggkt.utils.LogTool;
import com.atguigu.ggkt.utils.SpringTool;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.exception.ValidationException;
import com.wechat.pay.java.core.notification.NotificationConfig;
import com.wechat.pay.java.core.notification.NotificationParser;
import com.wechat.pay.java.core.notification.RequestParam;
import com.wechat.pay.java.service.payments.model.Transaction;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.Objects;

@Service
@RefreshScope
public class WxPayNotifyImpl_v3 {

    @Value("${wechat.mpAppId}")
    private String mpAppId;
    @Value("${wechat.notifyUrl}")
    private String notifyUrl;
    @Value("${wechat.mch.id-1}")
    private String mchId1;
    @Value("${wechat.mch.id-1-privateKeyPath}")
    private String privateKeyPath;
    @Value("${wechat.mch.id-1-merchantSerialNumber}")
    private String merchantSerialNumber;
    @Value("${wechat.mch.id-1-apiV3Key}")
    private String apiV3Key;
    @Value("${wechat.mch.id-1-sign-pem}")
    private String signPem;

    @Resource
    SequenceFeignClient sequenceFeignClient;

//    public NotificationConfig buildConfig() throws Exception {
//
//        File file = new File(privateKeyPath);
//        if (!file.exists()) {
//            // 把base64字符串转成文件
//            LogTool.info(this.getClass(), "go to create private key file!");
//            Base64FileConversion.decodeBase64ToFile(signPem, file);
//        }
//
//        // 如果已经初始化了 RSAAutoCertificateConfig，可直接使用
//        // 没有的话，则构造一个
//        NotificationConfig config = new RSAAutoCertificateConfig.Builder()
//                .merchantId(mchId1)
//                .privateKeyFromPath(privateKeyPath)
//                .merchantSerialNumber(merchantSerialNumber)
//                .apiV3Key(apiV3Key)
//                .build();
//        System.out.println(">>> NotificationConfig ok");
//        return config;
//    }
}
